package com.bocai.eelly.activitys;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.bocai.eelly.R;
import com.bocai.eelly.common.BaseActivity;
import com.bocai.eelly.common.ToolbarHelper;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 面料详情
 */
public class FabricDetailActivity extends BaseActivity {

    @Bind(R.id.web_newsdetail)
    WebView webNewsDetail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);
        ButterKnife.bind(this);
        initView();
    }

    protected void initView() {
        ToolbarHelper.setup(this, R.string.str_title_fabric, R.mipmap.ic_back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        loadData();
    }

    private void loadData() {
        final ProgressBar bar = (ProgressBar)findViewById(R.id.my_profile_tracker);
            webNewsDetail.loadUrl("https://www.baidu.com/");
        webNewsDetail.getSettings().setJavaScriptEnabled(true);
        webNewsDetail.getSettings().setAllowFileAccess(true);
        webNewsDetail.getSettings().setDomStorageEnabled(true);
        webNewsDetail.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    bar.setVisibility(View.GONE);
                } else {
                    if (View.INVISIBLE == bar.getVisibility()) {
                        bar.setVisibility(View.VISIBLE);
                    }
                    bar.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }
        });
        webNewsDetail.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }


            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                webNewsDetail.loadUrl(url);
                return true;
            }
        });
    }


}
